using System;

namespace Game500.StServer.Src
{
  public delegate void PlayerLeftDelegate(NetworkPlayer player);

  public delegate void PlayerJoinedDelegate(NetworkPlayer player);

  public abstract class NetworkManager : IDisposable
  {
    public int Port { get; protected set; }

    #region IDisposable Members

    public abstract void Dispose();

    #endregion

    public event PlayerJoinedDelegate PlayerJoined;
    public event PlayerLeftDelegate PlayerLeft;

    protected void RaisePlayerLeftEvent(NetworkPlayer player)
    {
      if (PlayerLeft != null)
      {
        PlayerLeft(player);
      }
    }

    protected void RaisePlayerJoinedEvent(NetworkPlayer player)
    {
      if (PlayerJoined != null)
      {
        PlayerJoined(player);
      }
    }

    public abstract int BindToPortRange(int minPort, int maxPort);

    public abstract void Start();

    public static NetworkManager Create()
    {
      return new TcpServerNetworkManager();
    }
  }
}